import { UserProfilesAPI } from "@/request/api";

export default{
    namespaced:true,
    state:{
        cartTotal:9,
        userInfo:{
            nickName:"hj",
            coin:15,
            headImg:require("../../assets/img/userImg.f8bbec5e.png")
        }
    },
    mutations:{
        changeUserInfo(state,payload){
            state.cartTotal = payload.cartTotal;
            state.userInfo = payload.userInfo
        },
        // 初始化用户信息
        initUserInfo(state){
            state.cartTotal = 0
            state.userInfo = {
                nickName:"--",
                coin:0,
                headImg:require("../../assets/img/userImg.f8bbec5e.png")
            }
        }
    },
    actions:{
        async asyncChangeUserInfo({commit}){
            let res = await UserProfilesAPI()
            console.log("用户信息res",res.data);
            commit('changeUserInfo',res.data)
        }
    }
}